package com.java110.mall.openapi.bmo.impl;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.intf.acct.IIntegralWithdrawalV1InnerServiceSMO;
import com.java110.mall.openapi.bmo.IMallCommonApiBmo;
import com.java110.po.integral.IntegralWithdrawalPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("deleteIntegralWithdrawalBmoImpl")
public class DeleteIntegralWithdrawalBmoImpl implements IMallCommonApiBmo {
    @Autowired
    private IIntegralWithdrawalV1InnerServiceSMO integralWithdrawalV1InnerServiceSMOImpl;
    @Override
    public void validate(ICmdDataFlowContext context, JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "iwId", "iwId不能为空");
        Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
    }

    @Override
    public void doCmd(ICmdDataFlowContext context, JSONObject reqJson) {
        IntegralWithdrawalPo integralWithdrawalPo = BeanConvertUtil.covertBean(reqJson, IntegralWithdrawalPo.class);
        integralWithdrawalPo.setShopId(reqJson.getString("communityId"));
        int flag = integralWithdrawalV1InnerServiceSMOImpl.deleteIntegralWithdrawal(integralWithdrawalPo);

        if (flag < 1) {
            throw new CmdException("删除数据失败");
        }

        context.setResponseEntity(ResultVo.success());
    }
}
